﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Babel.ParserGenerator;
using Babel.Parser;
using dragonangel.phpProject.Language.DSL.Parser;

namespace dragonangel.phpProject.Language.DSL
{
    public enum CodeConditionOperator
    {
        And,
        Or,
        Lesser,
        LesserOrEqual,
        Equals,
        Greater,
        GreaterOrEqual,
        NotEquals,
        None
    }

    public class CodeConditionExpression : CodeExpression
    {
        public CodeConditionExpression(CodeExpression left, CodeExpression right, LexLocation begin, LexLocation end)
            : this(left, right, CodeConditionOperator.Equals, begin, end)
        {
        }

        public CodeConditionExpression(CodeExpression left, CodeExpression right, CodeConditionOperator op, LexLocation begin, LexLocation end)
            : base(begin, end)
        {
            this.left = left;
            this.right = right;
            this.op = op;
        }

        public CodeConditionExpression(CodeExpression simpleCondition, LexLocation begin, LexLocation end)
            : this(simpleCondition, new CodeConstant("true",begin,begin), begin, end)
        {
        }

        protected CodeConditionOperator op;
        public CodeConditionOperator Operator
        {
            get { return op; }
            set { op = value; }
        }

        protected CodeExpression left;
        public CodeExpression Left
        {
            get { return left; }
            set { left = value; }
        }

        protected CodeExpression right;
        public CodeExpression Right
        {
            get { return right; }
            set { right = value; }
        }

        public static CodeConditionOperator GetOperatorFromToken(Tokens token)
        {
            switch (token)
            {
                case Tokens.EQ:
                    return CodeConditionOperator.Equals;
                case Tokens.NEQ:
                    return CodeConditionOperator.NotEquals;
                case Tokens.GT:
                    return CodeConditionOperator.Greater;
                case Tokens.GTE:
                    return CodeConditionOperator.GreaterOrEqual;
                case Tokens.LT:
                    return CodeConditionOperator.Lesser;
                case Tokens.LTE:
                    return CodeConditionOperator.LesserOrEqual;
            }
            return CodeConditionOperator.None;
        }
    }
}
